package com.qinggeng.project.api.controller;

import com.qinggeng.common.utils.StringUtils;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.project.api.utils.EmojiUtils;
import com.qinggeng.project.system.domain.vo.GoodsKeyWordsVO;
import com.qinggeng.project.system.service.IGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "关键词模块")
@RestController
@Slf4j
@RequestMapping("${apiPath}/keywords")
public class ApiKeywordsController extends BaseController {

    @Autowired
    private IGoodsService goodsService;

    @ApiOperation("关键词列表")
    @ApiImplicitParams(
            @ApiImplicitParam(name="inputWord",value = "输入词",dataType = "String",paramType = "query",required = true)
    )
    @GetMapping("/list")
    public AjaxResult selectKeywordsList(String inputWord){
        try {
            //根据输入词查询关键词列表
            List<GoodsKeyWordsVO> keywordsDtoList= goodsService.selectKeyWord(inputWord);
            if(keywordsDtoList==null || keywordsDtoList.isEmpty()){
                keywordsDtoList=new ArrayList<>();
                return AjaxResult.success(keywordsDtoList);
            }
            return AjaxResult.success(keywordsDtoList);
        } catch (Exception e) {
            return AjaxResult.error("非法字符");
        }
    }


}
